package com.burgeon.backend.SHOP.rest;
/**
 * 根据导购查店铺
 */

import com.burgeon.backend.Rest.base.RESTBase;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.util.ArrayList;
import java.util.HashMap;

public class FindStoreByEmp extends RESTBase {

    private String ip;
    private String account;
    private String password;

    public FindStoreByEmp(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }

    /**
     * 发送并接收字符创
     * @return
     */

    public HashMap<String,String> getData(String id) throws Exception {
        String url = "http://"+ip+"/servlets/binserv/Rest";

        String str = RESULT(Data(id),url);
        System.err.println(str);
        String code = new JSONArray(str).getJSONObject(0).getString("code");
        String message = new JSONArray(str).getJSONObject(0).getString("message");
        if (!"0".equals(code)){
            throw new Exception(message);
        }
        JSONArray jsonArray = new JSONArray(str).getJSONObject(0).getJSONArray("rows");
        if(jsonArray.length()>0){
            HashMap<String,String> data = new HashMap<String,String>();
            data.put("store",jsonArray.getJSONArray(0).getString(0));
            data.put("emp",jsonArray.getJSONArray(0).getString(1));
            data.put("phone",jsonArray.getJSONArray(0).getString(2));
            data.put("NO",jsonArray.getJSONArray(0).getString(3));
            data.put("sex",jsonArray.getJSONArray(0).getString(4));
            data.put("customerup",jsonArray.getJSONArray(0).getString(5));
            return data;
        }
       return null;
    }

    private MultiValueMap Data(String code) {
        HashMap params = new HashMap();
        ArrayList columns = new ArrayList();//查询字段


        columns.add("'C_STORE_ID;NAME'");
        columns.add("'NAME'");
        columns.add("PHONE");
        columns.add("NO");
        columns.add("SEX");
        columns.add("'C_CUSTOMER_ID;NAME'");

        params.put("columns", columns);
        params.put("table", "C_V_EMPLOYEE");//表名

        HashMap paramss = new HashMap();
        String ac = "'"+ code+"'";
        paramss.put("column", "'ID'");
        paramss.put("condition", ac);
        params.put("params", paramss);

        return DATA("Query", params,account,password);
    }
    public static void main(String[] args) {
        FindStoreByEmp getRetailByVip = new FindStoreByEmp("8.130.161.41:55321", "nea@burgeon.com.cn", "burgeon55321");
        try {
            System.err.println(getRetailByVip.getData("1250"));

        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
